package com.lm.common.log.listener;

import com.lm.common.log.event.SysLogEvent;
import com.lm.upms.api.entity.SysOperLog;
import com.lm.upms.api.feign.RemoteLogService;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.event.EventListener;
import org.springframework.core.annotation.Order;
import org.springframework.scheduling.annotation.Async;

/**
 * 异步监听日志事件
 *
 * @author lm
 * @date 2019/7/9 10:07
 */
@Slf4j
@AllArgsConstructor
public class LogListener {

    private final RemoteLogService remoteLogService;

    @Async
    @Order
    @EventListener(SysLogEvent.class)
    public void listenOperLog(SysLogEvent event) {
        SysOperLog sysOperLog = (SysOperLog) event.getSource();
        remoteLogService.saveOperLog(sysOperLog);
        log.info("操作日志记录成功：{}", sysOperLog);
    }

}